using System.Windows;
using System.Windows.Media;

namespace Boggle.Net.Controls
{
    public class ArrowPolyLine : ArrowLineBase
    {
        #region Dependency Properties

        /// <summary>
        ///     Identifies the Points dependency property.
        /// </summary>
        public static readonly DependencyProperty PointsProperty =
            DependencyProperty.Register("Points", typeof(PointCollection), typeof(ArrowPolyLine),
                new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsMeasure));

        /// <summary>
        ///     Gets or sets a collection that contains the 
        ///     vertex points of the ArrowPolyLine.
        /// </summary>
        public PointCollection Points
        {
            set { SetValue(PointsProperty, value); }
            get { return (PointCollection)GetValue(PointsProperty); }
        }

        #endregion

        public ArrowPolyLine()
        {
            Points = new PointCollection();
        }

        protected override Geometry DefiningGeometry
        {
            get
            {
                // Clear out the PathGeometry.
                PathGeometry.Figures.Clear();

                if (Points == null)
                {
                    PolyLine.Points.Clear();
                }
                else if (Points.Count > 0)
                {
                    // Define a PathFigure containing the points.
                    PathFigure.StartPoint = Points[0];
                    PolyLine.Points.Clear();

                    for (var i = 1; i < Points.Count; ++i)
                        PolyLine.Points.Add(Points[i]);

                    PathGeometry.Figures.Add(PathFigure);
                }

                // Call the base property to add arrows on the ends.
                return base.DefiningGeometry;
            }
        }
    }
}